<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>这里是主页面</h1>
<div>
    欢迎：<span id="uname"></span>
    <button onclick="logou()">
        退出登录
    </button>
</div>
<script>

    function logou(){
        fetch('/logout')
            .then(response => {
                if (response.ok) {
                    location.href = 'login.html';
                } else {
                    console.error('退出登录失败');
                }
            })
            .catch(error => console.error('Error during logout:', error));
    }
    document.addEventListener("DOMContentLoaded", function() {
    fetch('/getvalue')
        .then(response => response.json())
        .then(data => {
            var name = data.name;
            if(!name){
                window.location.href = "login.html"
            }
            document.getElementById("uname").innerHTML = name;
        })
        .catch(error => console.error('Error fetching session value:', error));
    });
</script>
</body>
</html>
